from django.db import models
from main.models import Book
from user.models import CustomUser


class MyLike(models.Model):
	user = models.ForeignKey(verbose_name="用户", to=CustomUser, on_delete=models.CASCADE)
	book = models.ForeignKey(verbose_name="壁纸", to=Book, on_delete=models.CASCADE)
	time = models.DateTimeField(verbose_name="添加时间", auto_now_add=True)

	def __str__(self):
		return self.user.username + "\t喜欢\t" + self.book.title

	class Meta:
		unique_together = [['user', 'book']]


class MyCollect(models.Model):
	user = models.ForeignKey(verbose_name="用户", to=CustomUser, on_delete=models.CASCADE)
	book = models.ForeignKey(verbose_name="壁纸", to=Book, on_delete=models.CASCADE)
	time = models.DateTimeField(verbose_name="收藏时间", auto_now_add=True)

	def __str__(self):
		return self.user.username + "\t收藏\t" + self.book.title

	class Meta:
		unique_together = [['user', 'book']]


class MyDownLoad(models.Model):
	user = models.ForeignKey(verbose_name="用户", to=CustomUser, on_delete=models.CASCADE)
	book = models.ForeignKey(verbose_name="壁纸", to=Book, on_delete=models.CASCADE)
	time = models.DateTimeField(verbose_name="下载时间", auto_now_add=True)
	state = models.BooleanField(verbose_name="下载状态", choices=(
		(True, "下载成功"),
		(False, "下载失败")
	), default=False)

	def __str__(self):
		return self.user.username + "\t收藏\t" + self.book.title

	class Meta:
		unique_together = [['user', 'book']]
